const  { MemoryCache } = require('memory-cache-node');

const itemsExpirationCheckIntervalInSecs = 10 * 60;
const maxItemCount = 10000;
const memoryCache = new MemoryCache(itemsExpirationCheckIntervalInSecs, maxItemCount);

module.exports = {
    set: (key, val, timeToLiveInSecs) => {
        if (!timeToLiveInSecs) {
            memoryCache.storePermanentItem(key, val);
        } else {
            memoryCache.storeExpiringItem(key, val, timeToLiveInSecs);
        }
    },
    get: (key) => {
        return memoryCache.retrieveItemValue(key);
    },
    del: (key) => {
        memoryCache.removeItem(key);
    },
    exists: (key) => {
        return memoryCache.hasItem(key);
    }
};